module fn.adt.graph.transform.Apply


open QuickGraph



let apply_to_graph (func : 'TVertex -> 'Range) (g : IEdgeListGraph<'TVertex,_>) =
    let g' = BidirectionalGraph<'Range,IEdge<'Range>>()
    for u in g.Vertices do
        g'.AddVertex (func u) |> ignore
    for e in g.Edges do
        let e' =
            match e :> IEdge<_> with
            | :? ITagged<'TVertex> as x -> TaggedEdge(func e.Source, func e.Target, func x.Tag) :> IEdge<_>
            | _ -> Edge(func e.Source, func e.Target) :> IEdge<_>
        g'.AddEdge (e') |> ignore
    g'
